import time

from selenium import webdriver

class Qzone(object):
    def __init__(self):
        self.Chormdriver = webdriver.Chrome()
        self.url = "https://qzone.qq.com/"
        self.number = "XXXXXXXXXXX"
        self.pasword = "XXXXXXXXXX"

    def __del__(self):
        self.Chormdriver.close()

    def size_element(self):
        self.Chormdriver.switch_to.frame('login_frame')
        b = self.Chormdriver.find_element_by_id('switcher_plogin')
        b.click()
        number_element = self.Chormdriver.find_element_by_xpath('//*[@id="u"]')
        password_element = self.Chormdriver.find_element_by_xpath('//*[@id="p"]')
        login_button = self.Chormdriver.find_element_by_xpath('//*[@id="login_button"]')
        time.sleep(1)
        return number_element, password_element, login_button

    def operation_element(self, number_element, password_element, login_button):
        number_element.send_keys(self.number)
        password_element.send_keys(self.pasword)
        login_button.click()


    def open_Chormdriver(self):
        self.Chormdriver.get(self.url)


    def star(self):
        # 打开浏览器
        self.open_Chormdriver()
        # 获取元素
        number_element, password_element, login_button = self.size_element()
        # 操作元素
        self.operation_element(number_element, password_element, login_button)


if __name__ == '__main__':
    Qzone = Qzone()
    Qzone.star()